/**Nico
 * 查询数据是否存在表格中 */
import { actionsTask } from '@ve/eventTask/index'
import isEmpty from 'lodash/isEmpty'
export default function dataInsertTable({ vm, module, action, callbackData, additionalData, done, eventName }) {
  console.log('vm -------------- ', vm)
  console.log('eventName -------------- ', eventName)
  console.log('来了来了-------------- ', eventName)
  let taskFlag = logicJudgeFunc(vm, module, action, callbackData)
  if (taskFlag) {
    actionsTask(
      vm,
      module,
      action.actions,
      additionalData,
      () => {
        console.log('子队列完成了', vm[`${eventName}IsRunning`], eventName)
        // 修改任务队列执行状态，防止下一次事件被拦截
        vm[`${eventName}IsRunning`] = false
      },
      eventName
    )
  } else {
    console.log('继续了')
    done(null, callbackData)
  }
  function logicJudgeFunc(vm, module, action, callbackData) {
    let { source } = action.extension.TableObject.value
    let value = action.extension.getDataKey.value

    if (!isEmpty(callbackData)) {
      // 选择输入框的值
      const formItem = vm.vuiComponents[source[0]] //获取选中得组件
      console.log('source', source[0], vm.vuiComponents, formItem)
      if (!isEmpty(formItem)) {
        const tdData = formItem.self.tdData //表格数据
        let someBool = false //true有一个不等于空
        someBool = tdData.some((v) => {
          if (v[value]) {
            return v[value] == Object.values(callbackData)[0]
          } else {
            return false
          }
        })
        console.log('someBool', someBool)
        return someBool
      }
    } else {
      return false
      // done(null, callbackData)
    }
  }
}
